package com.itheima.work;

import java.io.*;

/**
 * @auther Macrydy
 * @date 2020/7/8 10:31
 */
public class FileUtil implements Runnable {
    private static String str1;
    private static String str2;


    public FileUtil() {
    }

    public FileUtil(String str1, String str2) {
        this.str1 = str1;
        this.str2 = str2;
    }

    @Override
    public void run() {
        try {
            copyFicle();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void copyFicle() throws IOException {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(str1));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(str2));

        long start = System.currentTimeMillis();
        int len;
        while ((len=bis.read())!=-1){
            bos.write(len);
            bos.flush();
        }

        bos.close();
        bis.close();

        long end = System.currentTimeMillis();
        System.out.println(Thread.currentThread().getName()+"复制完成=====>用时："+(end-start)+"毫秒");

    }


}
